﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace WebDemo
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //注册按钮
            this.ScriptManager1.RegisterAsyncPostBackControl(btnReload);
        }

        protected void btnReload_Click(object sender, EventArgs e)
        {
            if (Timer1.Enabled)
            {
                //停止计时Tick
                Timer1.Enabled = false;
                //刷新按钮的Text
                btnReload.Text = "开始刷新";
                this.UpdatePanel2.Update();//刷新UpdatePanel2中的控件
            }
            else
            {
                int i = 3;
                try
                {
                    i = Convert.ToInt32(txtTimerInterval.Text.Trim());
                }
                catch (Exception)
                {
                }
                Timer1.Interval = i * 1000;//设置时钟间隔(s)
                Timer1.Enabled = true; //开始Tick

                //刷新按钮的Text
                btnReload.Text = "停止刷新";
                this.UpdatePanel2.Update();//刷新UpdatePanel2中的控件
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            //绑定txtTime控件
            txtTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            //绑定GridView1控件
            var random = new Random();
            List<WoDTO> objs = new List<WoDTO>();
            for (int i = 1; i <= 30; i++)
            {
                objs.Add(new WoDTO()
                {
                    Id = i,
                    Group = txtGroup.Text,
                    Wo = DateTime.Now.ToString("yyyy-MM-dd-" + i.ToString("##")),
                    Qty = random.Next(100000)
                });
            }
            GridView1.DataSource = objs;
            GridView1.DataBind();
            this.UpdatePanel1.Update(); //刷新UpdatePanel1中的控件
        }
    }
}